package com.baturu.vin.honda.dal.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * mdb导入mysql，mysql的DAO
 *
 * @author chenjiahao
 * @time 2018年6月26日 09:58:24
 */
public interface HondaDataTransferDAO {
    @Select("${sql}")
    List<Map<String, Object>> query(@Param("sql") String sql);

    @Update("${sql}")
    void ddl(@Param("sql") String sql);

    @Insert("<script>" +
            "INSERT INTO ${table}" +
            "<foreach item='item' collection='cols' open='(' close=')' separator=','>" +
            "${item}" +
            "</foreach> " +
            "VALUES " +
            "<foreach item='item'  collection='values' separator=','>" +
            "<foreach item='jtem' collection='item' open='(' close=')' separator=','>" +
            "#{jtem}" +
            "</foreach> " +
            "</foreach> " +
            "</script>")
    int batchInsert(@Param("table") String table, @Param("cols") List<String> cols, @Param("values") List<List<Object>> values);

    /**
     * 记录完成的表
     *
     * @param table
     * @return
     */
    @Insert("INSERT INTO finish_table(name,`date`) VALUES (#{table},now())")
    int finishTable(@Param("table") String table);

    /**
     * 查询完成的表
     *
     * @param table
     * @return
     */
    @Select("SELECT count(*) from finish_table where name = #{table} AND date(`date`) = date(now())")
    int queryFinishTable(@Param("table") String table);

}
